package com.bw.module_patrol.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.coroutine.CoroutineHelper
import com.bw.lib_common.vm.BaseViewModel2
import com.bw.module_attendance.repo.PatrolRepo
import com.bw.module_patrol.entity.PatrolEntity
import kotlinx.coroutines.launch

/**
 * 工单-智慧园区-巡逻管理
 */
class PatrolViewModel :BaseViewModel2<PatrolRepo>(){
    val patrolSuccess by lazy { MutableLiveData<List<PatrolEntity>>() }

    fun getPatrol(){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result = mRepository.getPatrol()
            if (result.code == 200){
                patrolSuccess.postValue(result.data)
            } else {
                mErrorLiveData.postValue("数据异常！！")
            }
        }
    }


    val updatePatrolSuccess by lazy { MutableLiveData<PatrolEntity>() }

    fun updatePatrol(id:Int, patrolEntity: PatrolEntity){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result = mRepository.updatePatrol(id, patrolEntity)
            if (result.code == 200){
                updatePatrolSuccess.postValue(result.data)
            } else {
                mErrorLiveData.postValue("数据异常！！")
            }
        }
    }



    override fun createRepository(): PatrolRepo = PatrolRepo()

}